package JAVA300.第十章IO;

/**
 * 借用放大声音的例子理解装饰器模式
 */

public class IO_Study09_decorateDemo {
    public static void main(String[] args) {
        person p = new person();
        p.say();

        //装饰
        Amplifier am = new Amplifier(p);
        am.say();
    }



}

interface Say{
    void say();
}


class person implements Say{
    private int voice = 10;

    @Override
    public void say() {
        System.out.println("声音是"+this.getVoice());
    }

    public int getVoice() {
        return voice;
    }
}

class Amplifier implements Say{
    private person p;

    public Amplifier(person p) {
        this.p = p;//在构造器中加入对p的修饰
    }

    @Override
    public void say() {
        System.out.println("声音是"+p.getVoice()*100);
        System.out.println("噪音a");
    }

}

